<?php
    session_start();
    $myUri = (empty($_SERVER['HTTPS']))?'http://':'https://';
    $myUri .= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    if (is_null($_SESSION['wechat_openid'])) {
        $ticket = $_GET['access_ticket'];
        if (is_null($ticket)) {
        $html = "<html><head><meta http-equiv='refresh' content='1;url="
                . "http://auth.bbpaina.com/wechat/oauth.php?wx=" . "aoershi" . "&url=" . urlencode($myUri) . "'></head><body>"
                ."<img src='http://cimg.bbpaina.com/ad/auth/cutebaby.jpg' style='width:100%;'>"
                ."</body><html>";
        die($html);
        } else {
            $res = file_get_contents('http://auth.bbpaina.com/wechat/get.php?ver=0.1&ticket='.$_GET['access_ticket']);
            $json = json_decode($res, true);
            if ($json['status'] == 'ok') {
                $_SESSION['wechat_openid'] = $json['result']['open_id'];
                $openid = $json['result']['open_id'];
            }
        }
    }
    